/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferAc10;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferAc10Service;
import me.zhengjie.modules.transfer.domain.dto.TransferAc10QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferAc10Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-26
**/
@Service
@RequiredArgsConstructor
public class TransferAc10ServiceImpl extends ServiceImpl<TransferAc10Mapper, TransferAc10> implements TransferAc10Service {

    private final TransferAc10Mapper transferAc10Mapper;

    @Override
    public PageResult<TransferAc10> queryAll(TransferAc10QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferAc10Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferAc10> queryAll(TransferAc10QueryCriteria criteria){
        return transferAc10Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferAc10 resources) {
        transferAc10Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferAc10 resources) {
        TransferAc10 transferAc10 = getById(resources.getAaz655());
        transferAc10.copy(resources);
        transferAc10Mapper.updateById(transferAc10);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferAc10Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferAc10> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferAc10 transferAc10 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("联系函编号", transferAc10.getAae270());
            map.put("人员编号", transferAc10.getAac001());
            map.put("人员参保关系 ID", transferAc10.getAaz159());
            map.put("社会保障号码", transferAc10.getAac002());
            map.put("姓名", transferAc10.getAac003());
            map.put("业务流程状态", transferAc10.getAae802());
            map.put("备注", transferAc10.getAae013());
            map.put("经办人", transferAc10.getAae011());
            map.put("经办时间", transferAc10.getAae036());
            map.put("经办地行政区划代码", transferAc10.getAab359());
            map.put("业务日志ID", transferAc10.getAaz002());
            map.put("人员参保关系转移接续类型", transferAc10.getBac617());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
